import * as _ from "lodash"
import httpClient from "../httpclient"

export namespace Analytics {
  export namespace Store {

    export class StoreTotalOrderQuantity {
      private pending_quantity: number = 0
      private awaiting_payment_quantity: number = 0
      private awaiting_fulfillment_quantity: number = 0
      private awaiting_shipment_quantity: number = 0
      private partially_shipped_quantity: number = 0
      private shipped_quantity: number = 0
      private awaiting_pickup_quantity: number = 0
      private partially_refunded_quantity: number = 0
      private refunded_quantity: number = 0
      private disputed_quantity: number = 0
      private cancelled_quantity: number = 0
      private completed_quantity: number = 0
      private declined_quantity: number = 0

      public get pendingQuantity() {
        return this.pending_quantity
      }

      public get awaitingPaymentQuantity() {
        return this.awaiting_payment_quantity
      }

      public get awaitingFulfillmentQuantity() {
        return this.awaiting_fulfillment_quantity
      }

      public get awaitingShipmentQuantity() {
        return this.awaiting_shipment_quantity
      }

      public get partiallyShippedQuantity() {
        return this.partially_shipped_quantity
      }

      public get shippedQuantity() {
        return this.shipped_quantity
      }

      public get awaitingPickupQuantity() {
        return this.awaiting_pickup_quantity
      }

      public get partiallyRefundedQuantity() {
        return this.partially_refunded_quantity
      }

      public get refundedQuantity() {
        return this.refunded_quantity
      }

      public get disputedQuantity() {
        return this.disputed_quantity
      }

      public get cancelledQuantity() {
        return this.cancelled_quantity
      }

      public get completedQuantity() {
        return this.completed_quantity
      }

      public get declinedQuantity() {
        return this.declined_quantity
      }
    }

    export class StoreTotalProductQuantity {
      private active_quantity = 0
      private archived_quantity = 0
      private pending_quantity = 0
      private disapproved_quantity = 0

      public get activeQuantity() {
        return this.active_quantity
      }

      public get archivedQuantity() {
        return this.archived_quantity
      }

      public get pendingQuantity() {
        return this.pending_quantity
      }

      public get disapprovedQuantity() {
        return this.disapproved_quantity
      }
    }

    export class StoreReportService {
      public static countTotalOrderQuantity(storeId: string): Promise<StoreTotalOrderQuantity> {
        return httpClient.get(`/v1/stores/${storeId}/reports/total_order_quantity`)
          .then(({ data }) => _.assign(new StoreTotalOrderQuantity(), data))
      }

      public static countTotalProductQuantity(storeId: string): Promise<StoreTotalProductQuantity> {
        return httpClient.get(`/v1/stores/${storeId}/reports/total_product_quantity`)
          .then(({ data }) => _.assign(new StoreTotalProductQuantity(), data))
      }
    }
  }
}
